package org.mzx.shortLink.adminn.controller;

import lombok.RequiredArgsConstructor;

import org.mzx.shortLink.starter.convention.Result.Result;
import org.mzx.shortLink.starter.web.Results;
import org.mzx.shortLink.adminn.dto.Request.ShortLinkGroupSaveReqDTO;
import org.mzx.shortLink.adminn.dto.Request.groupSortDtoReq;
import org.mzx.shortLink.adminn.dto.Request.groupUpdateDtoResp;
import org.mzx.shortLink.adminn.dto.Response.groupTypeDtoResp;
import org.mzx.shortLink.adminn.service.TGroupService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class TGroupController {

    private final TGroupService service;


    /**
     * 创建新的分组
     * */
    @PostMapping("/api/short-link/admin/v1/group")
    public Result<Void> createGroup(@RequestBody ShortLinkGroupSaveReqDTO requestParam) {
        return Results.success(service.createGroup(requestParam));
    }

    /**
     * 查询当前登录用户的短链接分组名称
     * */

    @GetMapping("/api/short-link/admin/v1/group")
    public Result<List<groupTypeDtoResp>> selectGroup() {
        return Results.success(service.selectGroup());
    }

    /**
     * 更新分组名
     * */

    @PutMapping("/api/short-link/admin/v1/group")
    public Result<Void> update(@RequestBody groupUpdateDtoResp requestParam) {
        return Results.success(service.Update(requestParam));
    }
    /**
     * 删除某个分组
     * */

    @DeleteMapping("/api/short-link/admin/v1/group")
    public Result<Void> delete(@RequestParam("gid") String gid) {
        return Results.success(service.delete(gid));
    }


    /**
     * 根据前端传入的顺序改变数据库中的ordernum
     * */
    @PostMapping("/api/short-link/admin/v1/group/sort")
    public Result<Void> sort(@RequestBody List<groupSortDtoReq> gids) {
        return Results.success(service.sort(gids));
    }
}
